home *** CD-ROM | disk | FTP | other *** search
/ An Introduction to Progr…l Basic 6.0 (4th Edition) / An Introduction to Programming using Visual Basic 6.0.iso / PROGRAMS / CH8 / 8-2-2.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-09-18  |  4.5 KB  |  155 lines

  1. VERSION 5.00
  2. Begin VB.Form frmMerge 
  3.    Caption         =   "Merge Two Files"
  4.    ClientHeight    =   2040
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1485
  7.    ClientWidth     =   3495
  8.    BeginProperty Font 
  9.       Name            =   "MS Sans Serif"
  10.       Size            =   8.25
  11.       Charset         =   0
  12.       Weight          =   700
  13.       Underline       =   0   'False
  14.       Italic          =   0   'False
  15.       Strikethrough   =   0   'False
  16.    EndProperty
  17.    LinkTopic       =   "Form1"
  18.    PaletteMode     =   1  'UseZOrder
  19.    ScaleHeight     =   2040
  20.    ScaleWidth      =   3495
  21.    Begin VB.PictureBox picProgress 
  22.       Height          =   255
  23.       Left            =   360
  24.       ScaleHeight     =   195
  25.       ScaleWidth      =   2715
  26.       TabIndex        =   7
  27.       Top             =   1680
  28.       Width           =   2775
  29.    End
  30.    Begin VB.CommandButton cmdProceed 
  31.       Caption         =   "Proceed to Merge"
  32.       Height          =   375
  33.       Left            =   720
  34.       TabIndex        =   6
  35.       Top             =   1200
  36.       Width           =   2055
  37.    End
  38.    Begin VB.TextBox txtNameMerged 
  39.       Height          =   285
  40.       Left            =   2160
  41.       TabIndex        =   5
  42.       Top             =   840
  43.       Width           =   1215
  44.    End
  45.    Begin VB.TextBox txtNameSecond 
  46.       Height          =   285
  47.       Left            =   2160
  48.       TabIndex        =   3
  49.       Top             =   480
  50.       Width           =   1215
  51.    End
  52.    Begin VB.TextBox txtNameFirst 
  53.       Height          =   285
  54.       Left            =   2160
  55.       TabIndex        =   1
  56.       Top             =   120
  57.       Width           =   1215
  58.    End
  59.    Begin VB.Label lblNameMerged 
  60.       Alignment       =   1  'Right Justify
  61.       Caption         =   "Name for merged file:"
  62.       Height          =   255
  63.       Left            =   120
  64.       TabIndex        =   4
  65.       Top             =   840
  66.       Width           =   1935
  67.    End
  68.    Begin VB.Label lblNameSecong 
  69.       Alignment       =   1  'Right Justify
  70.       Caption         =   "Name of second file:"
  71.       Height          =   255
  72.       Left            =   240
  73.       TabIndex        =   2
  74.       Top             =   480
  75.       Width           =   1815
  76.    End
  77.    Begin VB.Label lblNameFirst 
  78.       Alignment       =   1  'Right Justify
  79.       Caption         =   "Name of first file:"
  80.       Height          =   255
  81.       Left            =   360
  82.       TabIndex        =   0
  83.       Top             =   120
  84.       Width           =   1695
  85.    End
  86. Attribute VB_Name = "frmMerge"
  87. Attribute VB_GlobalNameSpace = False
  88. Attribute VB_Creatable = False
  89. Attribute VB_PredeclaredId = True
  90. Attribute VB_Exposed = False
  91. Private Sub cmdProceed_Click()
  92.   Dim file1 As String, file2 As String, file3 As String
  93.   Dim have1data As Boolean, have2data As Boolean
  94.   Dim num1 As Single, num2 As Single
  95.   Dim recCount As Integer
  96.   'Merge two ordered files
  97.   picProgress.Cls
  98.   file1 = txtNameFirst.Text
  99.   file2 = txtNameSecond.Text
  100.   file3 = txtNameMerged.Text
  101.   Open App.Path & "\" & file1 For Input As #1
  102.   Open App.Path & "\" & file2 For Input As #2
  103.   Open App.Path & "\" & file3 For Output As #3
  104.   have1data = Get1data(num1)
  105.   have2data = Get2data(num2)
  106.   recCount = 0
  107.   Do While have1data And have2data
  108.     Select Case num1
  109.       Case Is < num2
  110.         Write #3, num1
  111.         have1data = Get1data(num1)
  112.       Case Is > num2
  113.         Write #3, num2
  114.         have2data = Get2data(num2)
  115.       Case num2
  116.         Write #3, num1
  117.         have1data = Get1data(num1)
  118.         have2data = Get2data(num2)
  119.     End Select
  120.     recCount = recCount + 1
  121.   Loop
  122.   Do While have1data
  123.     Write #3, num1
  124.     recCount = recCount + 1
  125.     have1data = Get1data(num1)
  126.   Loop
  127.   Do While have2data
  128.     Write #3, num2
  129.     recCount = recCount + 1
  130.     have2data = Get2data(num2)
  131.   Loop
  132.   Close #1, #2, #3
  133.   picProgress.Print recCount; "records written to "; file3
  134. End Sub
  135. Private Function Get1data(num1 As Single) As Boolean
  136.   'If possible, read next value from file 1
  137.   'Return value True when new data is read; False if data not available
  138.   If Not EOF(1) Then
  139.       Input #1, num1
  140.       Get1data = True
  141.     Else
  142.       Get1data = False
  143.   End If
  144. End Function
  145. Private Function Get2data(num2 As Single) As Boolean
  146.   'If possible, read next value from file 2
  147.   'Return value True when new data is read; False if data not available
  148.   If Not EOF(2) Then
  149.       Input #2, num2
  150.       Get2data = True
  151.     Else
  152.       Get2data = False
  153.   End If
  154. End Function
  155.